﻿using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using EvincePayroll.Data;
using EvincePayroll.Logic;
using EvincePayroll.Utility;
using System.Configuration;

namespace Evince.Service
{
    // Start the service and browse to http://<machine_name>:<port>/Service1/help to view the service's generated help page
    // NOTE: By default, a new instance of the service is created for each call; change the InstanceContextMode to Single if you want
    // a single instance of the service to process all calls.	
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    // NOTE: If the service is renamed, remember to update the global.asax.cs file
    public class PageTemplateService
    {
        string userEmailId = ConfigurationManager.AppSettings["LoginID"].ToString();
        [WebGet(UriTemplate = "GetPageTemplate/{pageId}")]
        public PageTemplateData GetPageTemplate(string pageId)
        {
            try
            {
                PageTemplateLogic pageLogic = new PageTemplateLogic(userEmailId);
                return pageLogic.GetPageTemplate(pageId);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        [WebGet(UriTemplate = "GetPageTemplateList/")]
        public List<PageTemplateData> GetPageTemplateList()
        {
            try
            {
                PageTemplateLogic pageLogic = new PageTemplateLogic(userEmailId);
                return pageLogic.GetPageTemplateList();
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        [WebInvoke(UriTemplate = "AddPage/{email},{PageID}")]
        public bool AddPage(PageTemplateData page, string email, string PageID)
        {
            try
            {
                PageTemplateLogic pageLogic = new PageTemplateLogic(email);
                return pageLogic.AddPage(page, email, PageID);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        [WebGet(UriTemplate = "GetAllPageList/")]
        public List<PageTemplateData> GetAllPageList()
        {
            try
            {
                PageTemplateLogic pageLogic = new PageTemplateLogic(userEmailId);
                return pageLogic.GetAllPageList();
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        [WebGet(UriTemplate = "DeleteCMS/{pageId}")]
        public bool DeleteCMS(string pageId)
        {
            try
            {
                PageTemplateLogic pageLogic = new PageTemplateLogic(userEmailId);
                return pageLogic.DeleteCMS(pageId);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        [WebInvoke(UriTemplate = "AddGalleryPage/{emailId}")]
        public bool AddGalleryPage(GalleryData gallery, string emailId)
        {
            try
            {
                EmployeeLogic employee = new EmployeeLogic(emailId);
                return employee.AddGalleryPage(gallery);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        [WebGet(UriTemplate = "UpdateGalleryImage/{imageId},{status}")]
        public bool UpdateGalleryImage(string imageId, string status)
        {
            try
            {
                EmployeeLogic employee = new EmployeeLogic(userEmailId);
                return employee.UpdateGalleryImage(imageId, status);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        [WebGet(UriTemplate = "DeleteGalleryImage/{imageId}")]
        public bool DeleteGalleryImage(string imageId)
        {
            try
            {
                EmployeeLogic employee = new EmployeeLogic(userEmailId);
                return employee.DeleteGalleryImage(imageId);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        [WebGet(UriTemplate = "GetGallary/{emailId},{flag}")]
        public List<GalleryData> GetGallary(string emailId, string flag)
        {
            try
            {
                EmployeeLogic employee = new EmployeeLogic(emailId);
                return employee.GetGallary(Convert.ToBoolean(flag));
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }











    }
}